package zyc.dao.impl;

import zyc.dao.BookDao;
import zyc.pojo.Book;

import java.util.List;

/**
 * @description:
 * @author: ZhaoYicong
 * @date: Created in 2020/7/17 17:30
 * @version: v1.0
 * @modified By:
 */
public class BookDaoImpl extends BaseDao implements BookDao {


    @Override
    public int addBook(Book book) {
        String sql="insert into t_book  values(?,?,?,?,?,?,?)";
        int update = update(sql, book.getId(), book.getName(), book.getPrice(), book.getAuthor(), book.getSales(), book.getStock(), book.getImgPath());
        return update;
    }

    @Override
    public int deleteBookById(Integer id) {
        String sql="delete from t_book where id=?";
        int update = update(sql, id);
        return update;
    }

    @Override
    public int updateBook(Book book) {
        String sql = "update t_book set `name`=?,`author`=?,`price`=?,`sales`=?,`stock`=?,`img_path`=? where id = ?";
        return update(sql,book.getName(),book.getAuthor(),book.getPrice(),book.getSales(),book.getStock(),book.getImgPath(),book.getId());

    }

    @Override
    public Book queryBookById(Integer id) {
        String sql="select * from t_book where id=?";
        Book book = queryforone(Book.class, sql, id);
        return book;
    }

    @Override
    public List<Book> queryBooks() {
        String sql="select * from t_book";
        List<Book> bookList = queryforlist(Book.class, sql);
        return bookList;
    }
}
